package javax.core.common.mongo;

import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;

import javax.core.common.utils.GenericsUtils;
import java.io.Serializable;
import java.util.List;

public abstract class BaseDaoSupport<T extends Serializable,PK extends Serializable> {

    private EntityOperation<T> op;

    private MongoTemplate mongoTemplate;

    public BaseDaoSupport() {
        Class<T> entityClass = GenericsUtils.getSuperClassGenricType(getClass());
        this.op = new EntityOperation<T>(entityClass);
    }


    protected List<T> find(QueryRule queryRule){

        Query query = new Query();
        return mongoTemplate.find(query,op.entityClass);

    }

    protected void setMongoTemplate(MongoTemplate template){
        this.mongoTemplate = template;
    }
}
